<template>
  <div class="risk-compliance c-shadow">
    <jTabNav :items="tabList"></jTabNav>
    <div class="rzbgxx">
      <h4 class="detail-base-title d_jump" ref="operationState1">融资并购信息<span>{{(total + total4) || 0}}</span></h4>
      <j-no-data v-if="writData.length === 0 && writData4.length === 0" :mode="'b'" msg="b"></j-no-data>
      <div class="table-wrap" v-else>
        <div class="rongzi" v-if="writData.length !== 0">
          <h5 class="detail-base-title">
            融资信息
          </h5>
          <table>
            <thead>
              <tr>
                <th v-for="title in writ" :key="title">{{title}}</th>
              </tr>
            </thead>
            <tbody>
              <tr v-for="item in writData" :key="item.writ">
                <td>{{item.organizationShortName || '--'}}</td>
                <td>{{item.investMoney || '--'}}</td>
                <td>{{item.stockRatio || '--'}}</td>
                <td>{{item.investCount || '--'}}</td>
                <td>{{item.industry || '--'}}</td>
                <td>{{item.investDate | dateFormat}}</td>
              </tr>
            </tbody>
          </table>
          <div class="block paging-wrap fr">
            <el-pagination v-if="total>5"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page.sync="pageNum"
              :page-size="pageSize"
              layout="prev, pager, next, jumper"
              :total="total">
            </el-pagination>
          </div>
        </div>
        <div class="binggou" v-if="writData4.length !== 0">
          <h5 class="detail-base-title">
            并购信息
          </h5>
            <table>
            <thead>
              <tr>
                <th v-for="title in writ4" :key="title">{{title}}</th>
              </tr>
            </thead>
            <tbody>
              <tr v-for="item in writData4" :key="item.writ">
                <td>{{item.pubTime || '--'}}</td>
                <td>{{item.tradeTarget || '--'}}</td>
                <td>{{item.tradeMoney || '--'}}</td>
                <td>{{item.tradeCurrency || '--'}}</td>
                <td>{{item.stockRightPercent || '--'}}</td>
              </tr>
            </tbody>
          </table>
          <div class="block paging-wrap fr">
            <el-pagination v-if="total4>5"
              @size-change="handleSizeChange4"
              @current-change="handleCurrentChange4"
              :current-page.sync="pageNum4"
              :page-size="pageSize4"
              layout="prev, pager, next, jumper"
              :total="total4">
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
    <div class="zbxx clearFix">
        <h4 class="detail-base-title d_jump" ref="operationState2">中标信息<span>{{total3 || 0}}</span></h4>
        <j-no-data v-if="courtData.length === 0" :mode="'b'" msg="b"></j-no-data>
        <div class="table-wrap" v-else>
          <table>
            <thead>
              <tr>
                <th v-for="title in executor" :key="title">{{title}}</th>
              </tr>
            </thead>
            <tbody>
              <tr v-for="(item,index) in courtData" :key="index">
                <td>{{index + 1}}</td>
                <td>{{item.procurementName || '--'}}</td>
                <td>{{item.item || '--'}}</td>
                <td>{{item.purchaseCompanyName || '--'}}</td>
                <td>{{item.announcementTime | dateFormat}}</td>
              </tr>
            </tbody>
          </table>
          <div class="block paging-wrap fr">
            <el-pagination v-if="total3>5"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange3"
              :current-page.sync="pageNum3"
              :page-size="pageSize3"
              layout="prev, pager, next, jumper"
              :total="total3">
            </el-pagination>
          </div>
        </div>
    </div>
    <div class="zpxx clearFix">
        <h4 class="detail-base-title d_jump" ref="operationState3">招聘信息<span>{{total1 || 0}}</span></h4>
        <j-no-data v-if="sxData.length === 0" :mode="'b'" msg="b"></j-no-data>
        <div class="table-wrap" v-else>
          <table>
            <thead>
              <tr>
                <th v-for="title in employment" :key="title">{{title}}</th>
                <th>详情</th>
              </tr>
            </thead>
            <tbody>
              <tr v-for="(item,index) in sxData" :key="index">
                <td>{{index + 1}}</td>
                <td>{{item.job || '--'}}</td>
                <td>{{item.jobPropertity || '--'}}</td>
                <td>{{item.salary || '--'}}</td>
                <td>{{item.lowEducationBackgroud || '--'}}</td>
                <td>{{item.count || '--'}}</td>
                <td>{{item.publishDate | dateFormat}}</td>
                <td><button class="cancle-btn" @click="getInfo(sxData[index],9 ,1)"><span>查看</span> </button></td>
              </tr>
            </tbody>
          </table>
          <div class="paging-wrap feature_wrap fr">
          <el-pagination v-if="total1>5"
          @size-change="handleSizeChange"
            @current-change="handleCurrentChange1"
            :current-page.sync="pageNum1"
            :page-size.sync="pageSize1"
            layout="prev, pager, next, jumper"
            :total.sync="total1">
          </el-pagination>
        </div>
        </div>
    </div>
    <el-dialog title="详情" :visible.sync="show" width="80%">
      <div class="table-wrap dialog-wrap">
        <table>
          <tbody>
            <tr v-for="(item,idx) in contentKey" :key="idx" v-if="getValue(item)">
              <td width="18%" style="text-align:left">{{item}}</td>
              <td style="text-align:left">{{getValue(item)}}</td>
            </tr>
          </tbody>
        </table>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { jTabNav, jNoData } from '../../components'
import { sysSetting as api } from '../../api'
import { dir } from '../../assets/js/dir'
export default {
  data() {
    return {
      // 详情
      dialogContent: '',
      show: false,
      contentDir: [],
      contentKey: [],
      tabList: [],
      rzbg: 0,
      zbxx: 0,
      zpxx: 0,
      rz: 0,
      bg: 0,
      writ: ['投资方', '投资金额', '股权', '投资轮次', '行业', '投资时间'],
      writData: [],
      writ4: ['公告时间', '交易标的', '交易金额（万）', '币种', '股权交易比例（%）'],
      writData4: [],
      pageNum4: 1,
      pageSize4: 5,
      total4: 0,
      executor: ['序号', '招标名称', '品目', '招标单位', '发布时间'],
      courtData: [],
      employment: ['序号', '招聘职位', '工作性质', '职位月薪', '最低学位', '招聘人数', '发布时间'],
      sxData: [
        // {
        //   time: '2018-02-23',
        //   name: '金易融(湖北)网络科技有限公司',
        //   reference: '渝环监罚〔2017〕154号',
        //   court: '成都市青羊区人民法院'
        // },
        // {
        //   time: '2018-02-23',
        //   name: '金易融(湖北)网络科技有限公司',
        //   reference: '渝环监罚〔2017〕154号',
        //   court: '成都市青羊区人民法院'
        // },
        // {
        //   time: '2018-02-23',
        //   name: '金易融(湖北)网络科技有限公司',
        //   reference: '渝环监罚〔2017〕154号',
        //   court: '成都市青羊区人民法院'
        // }
      ],
      params: {},
      pageNum: 1,
      pageSize: 5,
      total: 0,
      pageNum1: 1,
      pageSize1: 5,
      total1: 0,
      pageNum3: 1,
      pageSize3: 5,
      total3: 0,
      number: '',
      entId: ''
    }
  },
  computed:{
    getValue() {
      return function(val) {
        let dialogContent = this.dialogContent
        if (typeof dialogContent === 'object') {
          let rtVal = dialogContent.get(val)
          return !isNaN(rtVal) && rtVal.toString().length === 13
            ? this.$options.filters['dateFormat'](rtVal)
            : rtVal
        } else {
          return false
        }
      }
    }
  },
  mounted() {
    this.params.entName = this.$route.query.entname
    this.getrongzibinggou() // 融资信息  数据  并购信息已开发
    this.getRealTimeDataWinbidList() // 中标信息
    this.getRealTimeDataJobPositionInfoList() // 招聘信息
  },
  methods: {
    // 查看详情
    getInfo(content, idx, num) {
      if (typeof num === 'number') {
        idx = num + idx
      }
      let contentDir = 'contentDir_' + idx
      this.contentDir = dir[contentDir]
      let contentKey = [...new Map(this.contentDir).values()]
      this.contentKey = contentKey
      this.changeInt(content)
      this.show = true
    },
    changeInt(content) {
      let conMap = new Map()
      let contentDir = new Map(this.contentDir)
      for (let key of Object.keys(content)) {
        let name = contentDir.get(key)
        conMap.set(name, content[key])
      }
      this.dialogContent = conMap
    },
    // 融资并购
    getrongzibinggou() {
      this.getRealTimeDataFindEntForeignInvestment()
      this.getRealTimeDataMergerList()
      if (!this.rzbg) {
        this.tabList.push({
          idx: 1,
          name: '融资并购信息',
          num: 0,
          offsetTop: this.$refs['operationState1'].offsetTop
        })
      }
      this.rzbg++
    },
    // 融资信息
    getRealTimeDataFindEntForeignInvestment() {
      // 数据源分页 数据有问题
      let _this = this
      let params = {
        pageNum: _this.pageNum,
        pageSize: _this.pageSize
      }
      api
        .getRealTimeDataFindEntForeignInvestment({ ..._this.params, ...params })
        .then(rtn => {
          if (!_this.rz) {
            _this.tabList.map(e => {
              if (e.name === '融资并购信息') {
                e.num += rtn.data.total || 0
                _this.rz++
              }
            })
          }
          if (!rtn.data) return false
          _this.writData = rtn.data.list
          _this.total = rtn.data.total
        })
        .catch(err => {
          _this.pageState = err
        })
    },
    handleSizeChange() {
      // 当pagesize改变的时候出发该函数
    },
    handleCurrentChange(index) {
      this.pageNum = index
      this.getRealTimeDataFindEntForeignInvestment()
    },
    // 并购信息
    getRealTimeDataMergerList() {
      let _this = this
      let params = {
        pageNum: _this.pageNum4,
        pageSize: _this.pageSize4
      }
      api
        .getRealTimeDataMergerList({ ..._this.params, ...params })
        .then(rtn => {
          if (!_this.bg) {
            _this.tabList.map(e => {
              if (e.name === '融资并购信息') {
                e.num += rtn.data.total || 0
                _this.bg++
              }
            })
          }
          if (!rtn.data) return false
          _this.writData4 = rtn.data.list
          _this.total4 = rtn.data.total
        })
        .catch(err => {
          _this.pageState = err
        })
    },
    handleSizeChange4() {
      // 当pagesize改变的时候出发该函数
    },
    handleCurrentChange4(index) {
      this.pageNum4 = index
      this.getRealTimeDataMergerList()
    },
    // 获取中标信息
    getRealTimeDataWinbidList() {
      let _this = this
      let params = {
        pageNum: _this.pageNum3,
        pageSize: _this.pageSize3
      }
      api
        .getRealTimeDataWinbidList({ ..._this.params, ...params })
        .then(rtn => {
          if (!_this.zbxx) {
            _this.tabList.push({
              idx: 2,
              name: '中标信息',
              num: rtn.data.total || 0,
              offsetTop: _this.$refs['operationState2'].offsetTop
            })
          }
          _this.zbxx++
          if (!rtn.data) return false
          _this.courtData = rtn.data.list
          _this.total3 = rtn.data.total
        })
        .catch(err => {
          _this.pageState = err
          if (!_this.zbxx) {
            _this.tabList.push({
              idx: 2,
              name: '中标信息',
              num: 0,
              offsetTop: _this.$refs['operationState2'].offsetTop
            })
          }
          _this.zbxx++
        })
    },
    handleCurrentChange3(index) {
      this.pageNum3 = index
      this.getRealTimeDataWinbidList()
    },
    // 获取招聘信息
    getRealTimeDataJobPositionInfoList() {
      let _this = this
      let params = {
        pageNum: _this.pageNum1,
        pageSize: _this.pageSize1
      }
      api
        .getRealTimeDataJobPositionInfoList({ ..._this.params, ...params })
        .then(rtn => {
          if (!_this.zpxx) {
            _this.tabList.push({
              idx: 3,
              name: '招聘信息',
              num: rtn.data.total || 0,
              offsetTop: _this.$refs['operationState3'].offsetTop
            })
          }
          _this.zpxx++
          if (!rtn.data) return false
          _this.sxData = rtn.data.list
          _this.total1 = rtn.data.total
        })
        .catch(err => {
          _this.pageState = err
          if (!_this.zpxx) {
            _this.tabList.push({
              idx: 3,
              name: '招聘信息',
              num: 0,
              offsetTop: _this.$refs['operationState3'].offsetTop
            })
          }
          _this.zpxx++
        })
    },
    handleCurrentChange1(index) {
      this.pageNum1 = index
      this.getRealTimeDataJobPositionInfoList()
    }
  },
  components: {
    jNoData,
    jTabNav
  }
}
</script>
<style lang="scss" scoped>
.risk-compliance {
  padding: 28px 40px;
  font-size: 14px;
  /deep/ .el-dialog__header {
    padding: 10px;
    background: #3f8ffa;
    .el-dialog__title {
      color: #fff;
    }
    .el-dialog__headerbtn {
      top: 12px;
      i {
        color: #fff;
      }
    }
  }
  .dialog-wrap {
    table {
      td,
      th {
        padding-left: 5px;
      }
    }
  }
  .detail-base-title {
    line-height: 30px;
    font-size: 16px;
    font-weight: bold;
    padding: 30px 0 0 12px;
    position: relative;
    background-image: linear-gradient(0deg,#1891ef,#1891ef);
    background-size: 3px 16px;
    background-position: 0 37px;
    background-repeat: no-repeat;
    border-bottom: 1px solid #eee;
  }
  h4.detail-base-title span {
    border: 1px solid #9dc5fd;
    border-radius: 10px;
    color: #1688f3;
    background: #f2f7ff;
    font-size: 12px;
    padding: 0 10px;
    margin-left: 15px;
    vertical-align: top;
  }
  .table-wrap {
    padding: 30px 20px;
    table {
      border-collapse: collapse;
      width: 100%;
      text-align: center;
      tr:hover {
        background: #f3f8ff;
      }
      td,
      th {
        border: 1px solid #e2e2e2;
        line-height: 40px;
      }
      th {
        line-height: 38px;
        color: #999;
        background: #f2f1f1;
      }
    }
  }
}
</style>




// WEBPACK FOOTER //
// src/view/clib/operationState.vue